<?php
/*
Plugin Name: * front end theme switcher
Plugin URI: http://wpprogrammeurs.nl
Description: lets (registered ?) users or visitors switch the currently active theme to another theme while on the front end
Author: pete scheepens , wpprogrammeurs.nl
Author URI: http://wpprogrammeurs.nl
Version: 1.2
*/

add_action('admin_menu', 'fets_menu',6);

function fets_menu(){
add_menu_page('theme switch','theme switch', 'manage_options', 'fets', 'fets_show_menu',plugins_url('sw16.png', __FILE__) );
}

function fets_show_menu() {
include_once(plugin_dir_path(__FILE__) . 'fets_menu.php');
}


add_action('plugins_loaded', 'switch_front',6);
function switch_front() 
{
	if (!empty($_REQUEST['theme']) && wp_verify_nonce($_REQUEST['fets'],'fets_switch'))
	{
	switch_theme($_REQUEST['theme'],$_REQUEST['theme']);
	$loc = $_SERVER['PHP_SELF'];
	header("Refresh: 1; url=$loc");
	echo "<div style='text-align:center;margin:5px auto;width:70%;padding:5px;border:2px solid red'><h1>One moment ... switching theme's</h1></div>";	
	}
}




add_action('wp_footer', 'show_front',6);
function show_front() {
$themes = wp_get_themes();
$fetsopts = get_option('fets_opts');
if ($fetsopts['loc'] == 'TL') echo "<div style='position:fixed;left:20px;top:80px;border:2px solid black;background-color:white;padding:10px;border-radius:10px'>";
elseif ($fetsopts['loc'] == 'TR') echo "<div style='position:fixed;right:200px;top:80px;border:2px solid black;background-color:white;padding:10px;border-radius:10px'>";
elseif ($fetsopts['loc'] == 'BL') echo "<div style='position:fixed;left:20px;bottom:40px;border:2px solid black;background-color:white;padding:10px;border-radius:10px'>";
elseif ($fetsopts['loc'] == 'BL') echo "<div style='position:fixed;right:200px;bottom:40px;border:2px solid black;background-color:white;padding:10px;border-radius:10px'>";
else echo "<div style='position:fixed;right:200px;bottom:40px;border:2px solid black;background-color:white;padding:10px;border-radius:10px'>";
?>
<form method='post'>
<select name='theme'>
<?PHP 
//if ($fetsopts['sort'] == 'AZ') $themes = asort($themes);
//if ($fetsopts['sort'] == 'ZA') $themes = arsort($themes);
$count = 0;
foreach ($themes as $theme)
{
$count++;
echo "<option value='". $theme->stylesheet . "'>". $theme->stylesheet . "</option>";
if ($fetsopts['maxcount']) {if ($count > $fetsopts['maxcount']) break;}
}
?>

</select><br/>
<?php wp_nonce_field('fets_switch','fets'); ?>
<input type='submit' value='switch theme'>
</form>
<?PHP
echo "</div>";
}